<?php
require_once '../../source/core/run.php';
require_once '../admin.inc.php';
$action		= Core_Fun::rec_post("action");
$page		= Core_Fun::detect_number(Core_Fun::rec_post("page"),1);

//$tpl->assign("mod",$mod);
//$tpl->display(ADMIN_TEMPLATE."frm_left.tpl");
 
 // list the days by month
 
switch($action){
    case 'edit';
	    edit();
		break;
	case 'saveedit';
	    saveedit();
		break;
	default:
	    volist();
		break;
}


function volist(){
	Core_Auth::checkauth("luck366volist");
	global $db,$tpl;
	$sql = "SELECT * FROM `tc_luck12`";		         
	$days = $db->getall($sql);
	//var_dump($days);
	
	$tpl->assign("today", date("Y-m-d"));
	$tpl->assign("listdata", $days);
}

function edit()
{
	Core_Auth::checkauth("luck12edit");
	global $db,$tpl;
    $id = Core_Fun::rec_post('id');
	
	if(!Core_Fun::isnumber($id)){
		Core_Fun::halt("ID丢失","",2);
	}
	$sql	= "SELECT * FROM `tc_luck12` WHERE uuid=$id";
	$cate	= $db->fetch_first($sql);
	if(!$cate){
		Core_Fun::halt("数据不存在","",2);
	}else{
	    $tpl->assign("id",$id);
	    $tpl->assign("cate",$cate);
	}
}

function saveedit()
{
	Core_Auth::checkauth("luck12add");
	global $db;
	$id			= Core_Fun::rec_post('id',1);
	$abstract		= Core_Fun::rec_post('abstract',1);
	$content		= Core_Fun::strip_post('content',1);
	
	$founderr	= false;
	if(!Core_Fun::isnumber($id)){
	    $founderr	= true;
		$errmsg	   .= "ID丢失.<br />";
	}
	if($founderr == true){
	    Core_Fun::halt($errmsg,"",1);
	}
	
	$array = array(
		'abstract'=>$abstract,
		'content'=>$content
	);
	//var_dump($array);
	echo mysql_error();
	$result = $db->update("`tc_luck12`",$array,"uuid=$id");
	if($result){
		Core_Command::runlog("","编辑运势365成功[id=$id]");
		Core_Fun::halt("编辑成功","luck12.php",0);
	}else{
		Core_Fun::halt("编辑失败","",2);
	}
}

$tpl->assign("action",$action);
$tpl->display("admin/yset/frm_list_luck12.tpl");
?>